package com.advertise.dao;

import java.io.Serializable;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class BaseDAO_Impl<PO,ID extends Serializable> extends HibernateDaoSupport implements
		BaseDAO_IFace<PO, ID> {

	private Class<PO> poClass;
	public BaseDAO_Impl(){
		poClass=(Class<PO>)GenericUtil.getGenericClass(this.getClass())[0];
	}
	
	
	public List<PO> getAll() {
		
		return getHibernateTemplate().loadAll(poClass);
	}

	@Override
	public boolean update(PO po) {
		try{
			getHibernateTemplate().update(po);
			return true;
		}
		catch (Exception e) {
			return false;
		}
		
	}

	@Override
	public boolean save(PO po) {
		try{
			getHibernateTemplate().saveOrUpdate(po);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
	}

	@Override
	public boolean deletebyID(ID id) {
		
		try{
			PO po=findByID(id);
			getHibernateTemplate().delete(po);
			return true;
		}
		catch (Exception e) {
			return false;
		}
		
	}

	@Override
	public boolean deleteByCollections(List<PO> collectionData) {
		try{
			getHibernateTemplate().deleteAll(collectionData);
			return true;
		}
		catch (Exception e) {
			return false;
		}
		
	}

	@Override
	public PO findByID(ID id){
		// TODO Auto-generated method stub
		return (PO)getHibernateTemplate().get(poClass, id);
	}

}
